package com.spotmanger.project.modular.spottable.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spotmanger.project.common.core.utils.DataResult;
import com.spotmanger.project.modular.spottable.entity.SpottableBaseEntity;
import com.spotmanger.project.modular.spottable.service.SpottableBaseService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/**
 * 图斑的基础信息表。该表中包含了图斑数据的公有基本信息，所有图斑数据均需要填写该表。
 *
 * @author leihao
 * @email 1321451088@qq.com
 * @date 2021-09-20 10:53:23
 */
@Controller
@RequestMapping("/")
public class SpottableBaseController {
    @Autowired
    private SpottableBaseService spottableBaseService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/spottableBase")
    public String spottableBase() {
        return "spottable/spottablebase/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("spottableBase/add")
    @RequiresPermissions("spottableBase:add")
    @ResponseBody
    public DataResult add(@RequestBody SpottableBaseEntity spottableBase){
        spottableBaseService.save(spottableBase);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("spottableBase/delete")
    @RequiresPermissions("spottableBase:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        spottableBaseService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("spottableBase/update")
    @RequiresPermissions("spottableBase:update")
    @ResponseBody
    public DataResult update(@RequestBody SpottableBaseEntity spottableBase){
        spottableBaseService.updateById(spottableBase);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("spottableBase/listByPage")
    @RequiresPermissions("spottableBase:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SpottableBaseEntity spottableBase){
        Page page = new Page(spottableBase.getPage(), spottableBase.getLimit());
        LambdaQueryWrapper<SpottableBaseEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(SpottableBaseEntity::getId, spottableBase.getId());
        IPage<SpottableBaseEntity> iPage = spottableBaseService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
